import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../provides/setting/modify_password.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class ModifyPassword extends StatefulWidget{
    _ModifyPasswordState createState() => _ModifyPasswordState();
}

class _ModifyPasswordState extends State<ModifyPassword>{

    TextEditingController _oldPassword = TextEditingController();
    TextEditingController _newPassword = TextEditingController();
    TextEditingController _newPassword2 = TextEditingController();


    @override
    Widget build(BuildContext context){
        return MultiProvider(
            providers: [
                ChangeNotifierProvider(builder: (_) => ModifyPasswordProvider()),
            ],
            child: Consumer<ModifyPasswordProvider>(
                builder: (context, counter, _) {
                    return Scaffold(
                        appBar: AppBar(
                            centerTitle: true,
                            title: Text("修改密码"),
                        ),
                        body:Container(
                            child: Column(
                                children: <Widget>[
                                    TextField(
                                        controller: _oldPassword,
                                        decoration: InputDecoration(
                                            labelText: "旧密码",
                                            hintText: "请输入旧密码",
                                            prefixIcon: Icon(Icons.event_note),
                                        ),
                                    ),
                                    TextField(
                                        controller: _newPassword,
                                        obscureText:true,
                                        decoration: InputDecoration(
                                            labelText: "新密码",
                                            hintText: "请输入新密码",
                                            prefixIcon: Icon(Icons.event_note),
                                        ),
                                    ),
                                    TextField(
                                        controller: _newPassword2,
                                        obscureText:true,
                                        decoration: InputDecoration(
                                            labelText: "新密码",
                                            hintText: "请输入新密码",
                                            prefixIcon: Icon(Icons.event_note),
                                        ),
                                    ),
                                    Container(
                                        width: double.infinity,
                                        height: ScreenUtil().setHeight(80),
                                        margin: EdgeInsets.all(20.0),
                                        child: FlatButton(
                                            color: Color.fromRGBO(81, 126, 219, 1),
                                            shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20.0)),
                                            child: Text(
                                                "修改密码",
                                                style: TextStyle(
                                                    color: Colors.white
                                                ),
                                            ),
                                            onPressed: (){
                                                Provider.of<ModifyPasswordProvider>(context).changePassword(context,_oldPassword.text,_newPassword.text,_newPassword2.text);
                                            },
                                        ),
                                    )
                                ],
                            ),
                        ) ,
                    );
                },
            ),
        );


        
    }

}